package com.iris.live.services.data.repositories;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.iris.live.services.data.models.IncomeAdjustmentModel;
import com.iris.live.services.data.models.Lsh经销商表Model;

import java.util.Date;

public interface IncomeAdjustmentRepository extends JpaRepository<IncomeAdjustmentModel, Integer>, JpaSpecificationExecutor<IncomeAdjustmentModel> {
	
	@Modifying
    @Query("DELETE FROM IncomeAdjustmentModel u WHERE u.id = ?1")
    int delIncomeAdjustmentById(Integer id);
	    
	
	@Query("select u from IncomeAdjustmentModel u where u.stockCode= ?1 and u.permit= ?2")
	IncomeAdjustmentModel getIncomeAdjustmentByStockCode(Integer stockCode, String permit);
	
	@Query("select u from IncomeAdjustmentModel u where u.carCode= ?1 and u.permit= ?2 and u.type=?3")
	IncomeAdjustmentModel getIncomeAdjustmentByCarCode(Integer carCode, String permit, String type);

	@Query("select u from IncomeAdjustmentModel u where u.pNum= ?1 and u.permit= ?2")
	IncomeAdjustmentModel getIncomeAdjustmentByPnum(Integer pnum, String permit);

	@Query("select u from IncomeAdjustmentModel u where u.permit= ?1 and u.type !=1 and u.validStartDate =?2 and u.validEndDate =?3 and  u.carCode= ?4 and u.type=?5 ")
	IncomeAdjustmentModel getIncomeAdjustmentByValidDate(String permit, Date start,Date end,Integer carCode, String type);

	@Query("select u from IncomeAdjustmentModel u where u.permit= ?1 and u.type !=1 and u.validStartDate =?2 and u.validEndDate =?3 and  u.carCode= ?4 and u.type=?5  and u.give= ?6 ")
	IncomeAdjustmentModel getIncomeAdjustmentByValidDateMarket(String permit, Date start,Date end,Integer carCode, String type,Boolean give);
}
